/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2023-11-19
 * Time: 12:05
 */

//因为源码的compareTo函数是强制类型转化为(comparable)，所以这里必须要和Comparable接口进行链接

//方法一:链接Comparable
//public class Student implements Comparable{
//
//    private String name;
//    private int score;
//
//    //构造方法
//    public Student(String name, int score) {
//        this.name = name;
//        this.score = score;
//    }
//
//
//    //Object类下的toString方法:
//    //以字符串的形式打印
//    public String toString() {
//        return "[" + this.name + ":" + this.score + "]";
//    }
//
//    @Override
//    public int compareTo(Object o) {
//
//        //这里利用的是向下赋值，把Object类 强制转化为student类
//        Student student = (Student)o;
//        return this.score - student.score;
//    }
//}


//方法二: 链接Comparable<Student>,直接在这里进行强制类型转化
public class Student implements Comparable<Student>{

    private String name;
    private int score;

    //构造方法
    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }


    //Object类下的toString方法:
    //以字符串的形式打印
    public String toString() {
        return "[" + this.name + ":" + this.score + "]";
    }

    @Override
    public int compareTo(Student o) {

        //这里利用的是向下赋值，把Object类 强制转化为student类
        Student student = (Student)o;
        return this.score - student.score;
    }
}


